﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using Facebook.Service.Core;

namespace Facebook.Service {

    /// <summary>
    /// Represents the service APIs that allow accessing admin information.
    /// </summary>
	/// <remarks>See http://wiki.developers.facebook.com/index.php/Admin.getAllocation</remarks>
    public sealed class AdminService
	{
        private FacebookSession _session;

		internal AdminService(FacebookSession session)
		{
            Debug.Assert(session != null);
            _session = session;
        }
		/// <summary>
		/// Get Email Disable Message Location
		/// </summary>
		/// <returns>AdminIntegrationPoint.email_disable_message_location value.  1 = top, 2 = bottom, -1 if request failed</returns>
		public int GetEmailDisableMessageLocation()
		{
			return GetAllocation(AdminIntegrationPoints.EmailDisableMessageLocation);
		}
		
        /// <summary>
        /// Gets the membership information for the specified event. This corresponds to the
        /// Facebook events.getMembers method.
        /// </summary>
		/// <param name="integrationPoint">notifications_per_day, requests_per_day, emails_per_day, and email_disable_message_location.</param>
        /// <returns>The Int32 value of the admin integration point name. -1 if request failed</returns>
		public int GetAllocation(AdminIntegrationPoints integrationPoint)
		{
			string integrationPointName;
			switch (integrationPoint)
			{
				case AdminIntegrationPoints.EmailDisableMessageLocation:
				{
					integrationPointName = "email_disable_message_location";
					break;
				}
				case AdminIntegrationPoints.EmailsPerDay:
				{
					integrationPointName = "emails_per_day";
					break;
				}
				case AdminIntegrationPoints.NotificationsPerDay:
				{
					integrationPointName = "notifications_per_day";
					break;
				}
				case AdminIntegrationPoints.RequestsPerDay:
				{
					integrationPointName = "requests_per_day";
					break;
				}
				default:
				{
					throw new ArgumentOutOfRangeException("Unknown AdminIntegrationPoint value passed to ");
				}

			}

            FacebookRequest request = new FacebookRequest(_session);
			request.Parameters["integration_point_name"] = integrationPointName;

			// execute the method
			FacebookResponse response = request.InvokeMethod("Admin.getAllocation");

			// check status and return the value
            if (response.Status == FacebookResponseStatus.Succeeded) {

				string result = FacebookResponse.CoerceString(response.Result);
				if (!String.IsNullOrEmpty(result))
				{
					return Int32.Parse(result);
				}
            }

            return -1;
        }
    }
}